﻿Imports BUS
Imports DTO
Public Class frmGiaHanThe : Inherits DevComponents.DotNetBar.Office2007Form
    Dim stt As Integer = 0
    Dim dto As CDocGiaDTO
    Private Function KiemTra() As Boolean
        If (txtMaDocGia.Text = "") Then
            MessageBox.Show("Mã độc giả không được để trống")
            Return False
        End If
        Dim n As Integer
        If Not Integer.TryParse(txtMaDocGia.Text, n) Then
            MessageBox.Show("Mã độc giả không đúng")
            Return False
        End If
        dto = New CDocGiaBUS().LayDocgiaKhiBietMaCoTheHetHan(Convert.ToInt32(txtMaDocGia.Text))
        If dto Is Nothing Then
            MessageBox.Show("Không có độc giả nào có mã như trên.")
            Return False
        End If
        Return True
    End Function
    Private Sub btnTim_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTim.Click
      
        If (Not KiemTra()) Then
            Return
        End If
        txtTenDocGia.Text = dto.HoTen
        dtpNgayHetHan.Value = dto.NgayHetHan

        Dim lphieumuon As List(Of CChiTietPhieuMuonDTO) = New CChiTiepPhieuMuonBUS().LayChiTietPhieuMuonTheoMa(Convert.ToInt32(txtMaDocGia.Text))
        For Each pm As CChiTietPhieuMuonDTO In lphieumuon
            stt += 1
            DataGridViewChiTiet.Rows.Add(stt, pm.MaPhieuMuon, pm.Ma, New CSachBUS().LayTenSach(pm.MaSach), pm.NgayMuon)
        Next

    End Sub

    Private Sub btnGiaHanThe_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGiaHanThe.Click
        If Not KiemTra() Then
            Return
        End If
        dtpNgayHetHan.Value = dtpNgayHetHan.Value.AddMonths(New CThamSoBUS().LayThoiHanThe())
        dto.NgayHetHan = dtpNgayHetHan.Value
        Dim n As Integer = New CDocGiaBUS().CapNhatNgayHetHan(dto)

    End Sub

    Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click
        txtMaDocGia.Text = ""
        txtTenDocGia.Text = ""
        DataGridViewChiTiet.Rows.Clear()

    End Sub
End Class